﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PacketRush.Core;
using System.Net;

namespace ConnectionTestServer
{
    class Program
    {
        private static bool _Running = true;
        static void Main(string[] args)
        {
            NetServer server = new NetServer(new ReliableUdpServerNetworkingProvider(), IPAddress.Parse("127.0.0.1"), 50000);
            server.Connected += new EventHandler<NetEventArgs>(server_Connected);
            server.Disconnected += new EventHandler<NetEventArgs>(server_Disconnected);
            server.Error += new EventHandler<NetErrorEventArgs>(server_Error);
            server.Start();

            while (_Running)
            {
                server.Update();

                if (Console.KeyAvailable)
                {
                    if (Console.ReadKey().Key == ConsoleKey.Escape)
                    {
                        _Running = false;
                    }
                }
            }

            server.Stop();
        }

        static void server_Error(object sender, NetErrorEventArgs e)
        {
        }

        static void server_Disconnected(object sender, NetEventArgs e)
        {
            Console.WriteLine(String.Format("{0} Disconnected.", e.ConnectionId));

        }

        static void server_Connected(object sender, NetEventArgs e)
        {
            Console.WriteLine(String.Format("{0} Connected.", e.ConnectionId));
        }
    }
}
